<?php
/**
 * @category     Inchoo
 * @package     Inchoo Featured Products
 * @author        Domagoj Potkoc, Inchoo Team <web@inchoo.net>
 * @modified    Mladen Lotar <mladen.lotar@surgeworks.com>, Vedran Subotic <vedran.subotic@surgeworks.com>
 */
?>
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
	<?php $this->addPriceBlockType('simple', 'catalog/product_price', 'catalog/product/price_product_view.phtml');?>
	<?php $this->addPriceBlockType('configurable', 'catalog/product_price', 'catalog/product/price_product_view.phtml');?>
	<div class="sales-home-banner-container">
		<div id="salesNav"></div>
		<div class="fade-items">
		<?php foreach ($_products->getItems() as $_product): ?>			
			<?php if($_product->getFinalPrice() < $_product->getPrice() && $_product->isSaleable()):?>
			<div class="item">
				<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
					<img width="715" height="360" class="product-img" src="<?php echo $this->helper('catalog/image')->init($_product, 'banner_image')->keepFrame(TRUE)->resize(715, 360) ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
				</a>
				<div class="sales-left">
					<h1 class="header">on sale:</h1>
					<div class="details">
						<h2 class="product-name">							
							<?php echo $this->htmlEscape($_product->getName()) ?>						
						</h2>
						<p class="product-description"><?php echo $_product->getShortDescription()?></p>
					</div>
					<?php echo $this->getPriceHtml($_product) ?>
					<div class="actions">
						<?php if($_product->isSaleable()): ?>							
							<div class="increase">
								<input type="text" readonly="readonly" id="qty-banner-<?php echo $_product->getId()?>" value="1"/>
								<span class="up pointer" onclick="increaseQty(false, false, true, <?php echo $_product->getId()?>, <?php echo $this->helper('gtgobbler/catalog')->getMaxIncreaseQty($_product)?>)">up</span>
								<span class="down pointer" onclick="decreaseQty(false, false, true, <?php echo $_product->getId()?>)">down</span>
							</div>
							<?php if ($_product->getTypeInstance(true)->hasOptions($_product)):?>
								<button id='mc-banner-<?php echo $_product->getId()?>' class="button arrow-down mcbutton"><span><span>more choices</span></span></button>
								<?php $configurableAttributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product)?>  
								<div class="select-flavour-container-list" id="flavourc-banner-<?php echo $_product->getId()?>">
								<?php foreach($configurableAttributes as $attribute):?>									
									<table>
										<col />
										<col width="35"/>
										<tbody>
											<?php $i=1;$count=count($attribute['values']);foreach($attribute['values'] as $value):?>
											<?php
												$childProduct = $_product->getTypeInstance(true)->getProductByAttributes(array($attribute['attribute_id'] => $value['value_index']), $_product);
												$childProduct = Mage::getModel('catalog/product')->load($childProduct->getId());
												if(!$childProduct->isSaleable()) 
													continue;
											?>
											<tr <?php if($i == $count) echo 'class="last"'?> onclick="addToCartAjax(<?php echo $_product->getId()?>, false, false, true, <?php echo $attribute['attribute_id']?>, <?php echo $value['value_index']?>)">												
												<td class="label">													
													<?php echo $value['label']?>													
												</td>
												<td class="addto">
													<span>add to</span>
													<span class="big">cart</span>
												</td>												
											</tr>
											<?php $i++?>
											<?php endforeach?>
										</tbody>
									</table>									
								<?php endforeach?>
								</div>
							<?php else:?>	
							<button type="button" title="<?php echo $this->__('add to cart') ?>" class="button btn-cart" onclick="addToCartAjax(<?php echo $_product->getId()?>, false, false, true)"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
							<?php endif?>
						<?php else: ?>
							<p class="availability out-of-stock"><span><?php echo $this->__('Sold Out') ?></span></p>
						<?php endif; ?>                    
					</div>
					<button class="button mvbutton" onClick="window.location='<?php echo $_product->getProductUrl() ?>'"><span><span>view more details</span></span></button>
				</div>
			</div>
			<?php endif?>
		<?php endforeach; ?>
		</div>
		<p id="an-banner" class="added-notify"></p>
	</div>
	<script type="text/javascript">
		jQuery(document).ready(function() {
			if(jQuery('.fade-items .item').length > 1){
				jQuery('.fade-items').cycle({			
					timeout: 10000,
					pager: '#salesNav'
				});
				
				jQuery('.fade-items').mouseover(function(){
					jQuery('.fade-items').cycle('pause');
				}).mouseout(function(){
					jQuery('.fade-items').cycle('resume');
				});
			}
			var hasEffect = false;		
			jQuery('.sales-home-banner-container .item').hoverIntent({
				over: function(){
					if(!hasEffect){
						hasEffect = true;
						jQuery('.sales-left', this).show("slide", { direction: "left" }, 'slow');
					}
				},
				out: function(){
					jQuery('.sales-left', this).hide("slide", { direction: "left" }, 'slow');
					hasEffect = false;
				},
				timeout: 500
			});
		});
	</script>
<?php endif; ?>